SRC=./src
COMPILE_ONLY =c
CFLAGS= -ansi  -pedantic -Wall
BIN=bin
OBJ=obj
CM=Common
PB=Public
ST=Static
DN=Dinamic
RL=../$(CM)/$(BIN)/Release

CC=gcc

Debug:   Debug_OR_Release=Debug
Debug:   CFLAGS+=-g 
Debug:   SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Debug:   OBJ_F=$(OBJ)/$(Debug_OR_Release)/useAPI.o

Release: Debug_OR_Release=Release
Release: CFLAGS+=-D_Debug_of_Schelduller -O2
Release: SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Release: OBJ_F=$(OBJ)/$(Debug_OR_Release)/useAPI.o



all: Release

Debug:   create_folders  OPsystemEXE  Install Clear 
Release: create_folders  OPsystemEXE  Install Clear

OPsystemEXE: user.obj schedul.obj kernel.obj $(SRC)/UserAPI.h  $(SRC)/Kernel.h $(SRC)/ST_Schelduller.h listing_act_Exe 
	g++ -o OPsystemEXE   -I $(SRC) $(OBJ_F)  ./$(OBJ)/$(Debug_OR_Release)/schedul.o ./$(OBJ)/$(Debug_OR_Release)/kernel.o ../$(CM)/$(BIN)/$(Debug_OR_Release)/libMemoryManager.a ../$(CM)/$(BIN)/$(Debug_OR_Release)/libqueue_inside.a

listing_act_Exe:
	@echo
	@echo "-----------------------------"
	@echo "   PRODUCING OPsystem EXECUT "
	@echo "-----------------------------"
	@echo

libkernsch.a:schedul.obj kernel.obj Ja ne znaju pochemu to cherez sifrijot eto ne rabotaet
	ar -r -s -o ./$(BIN)/$(Debug_OR_Release)/libkernsch.a  ./$(OBJ)/$(Debug_OR_Release)/schedul.o ./$(OBJ)/$(Debug_OR_Release)/kernel.o
 
schedul.obj: $(SRC)/ST_Schelduller.c $(SRC)/ST_Schelduller.h  $(SRC)/UserAPI.h 
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB) -$(COMPILE_ONLY) $(SRC)/ST_Schelduller.c -o ./$(OBJ)/$(Debug_OR_Release)/schedul.o 

kernel.obj: $(SRC)/Kernel.c $(SRC)/ST_Schelduller.h  $(SRC)/UserAPI.h  $(SRC)/Kernel.h 
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB) -$(COMPILE_ONLY) $(SRC)/Kernel.c  -o ./$(OBJ)/$(Debug_OR_Release)/kernel.o

user.obj: $(SRC)/Usermode.c $(SRC)/UserAPI.h  $(SRC)/Kernel.h 
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB) -$(COMPILE_ONLY) $(SRC)/Usermode.c -o $(OBJ_F)	


create_folders:
	-mkdir $(OBJ)
	-mkdir $(BIN)
	-mkdir $(OBJ)/$(Debug_OR_Release) 
	-mkdir $(BIN)/$(Debug_OR_Release)

Install:creat_instal_folders  CopyHfile 


CopyF: 
	cp $(BIN)/$(Debug_OR_Release)/libkernsch.a  ../$(CM)/$(BIN)/$(Debug_OR_Release)

CopyHfile:
	cp $(SRC)/Kernel.h ../Common/$(PB)
	cp $(SRC)/UserAPI.h ../Common/$(PB)
	cp $(SRC)/ST_Schelduller.h ../Common/$(PB)
		
creat_instal_folders:
	- mkdir ../$(CM)
	- mkdir ../$(CM)/$(BIN)
	- mkdir ../$(CM)/$(PB)
	- mkdir ../$(CM)/$(BIN)/$(Debug_OR_Release)


Clear:
	for i in $(SUBDIRS); do\
		(cd $$i; rm * );\
	done


	


